<template>
  <div>
    <el-card>
      <div slot="header">
        <div class="category">
          <span>销售额占比</span>
          <el-radio-group v-model="value">
            <el-radio-button label="全部渠道"></el-radio-button>
            <el-radio-button label="线上"></el-radio-button>
            <el-radio-button label="门店"></el-radio-button>
          </el-radio-group>
        </div>
      </div>
      <div></div>
    </el-card>
    <div ref="chars" class="chars"></div>
  </div>
</template>

<script>
import echarts from "echarts";
export default {
  data() {
    return {
      value: "全部渠道",
    };
  },
  mounted() {
    const myCharts = echarts.init(this.$refs.chars);
    myCharts.setOption({
      title:{
        text:'主标题',
        subtext:1048,
        left:"center",
        top:'center'
      },
      tooltip: {
        trigger: "item",
      },
      series: [
        {
          name: "Access From",
          type: "pie",
          radius: ["40%", "70%"],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: "#fff",
            borderWidth: 2,
          },
          label: {
            show: true,
            position: "outside",
          },
          labelLine: {
            show: true,
          },
          data: [
            { value: 1048, name: "视频" },
            { value: 735, name: "Direct" },
            { value: 580, name: "Email" },
            { value: 484, name: "Union Ads" },
            { value: 300, name: "Video Ads" },
          ],
        },
      ],
    });
    //为图标绑定事件
    myCharts.on('mouseover', (params)=>{
      //获取鼠标数据
      const {name,value} = params.data
      myCharts.setOption({
        title:{
          text:name,
          subtext:value
        }
      })
    });
  },
};
</script>

<style>
.category {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0px;
}
</style>
<style scoped>
>>> .el-card__header {
  padding: 5px;
}
.chars {
  width: 100%;
  height: 300px;
}
</style>
